<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" label-width="150px">
      <el-form-item label="音频输入开关" v-if="false">
        <el-switch
          v-model="form.iAudioInputEnable"
          :active-value="activeValue"
          :inactive-value="inactiveValue"
        ></el-switch>
      </el-form-item>
      <el-form-item label="音频输入" v-if="false">
        <el-select v-model="form.sAudioInput" placeholder="请选择音频输入">
          <el-option label="麦克风" value="mic"></el-option>
          <el-option label="线输入" value="wire"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="压缩格式" v-if="false">
        <el-select v-model="form.sCompressFormat" placeholder="请选择压缩格式">
          <el-option label="pcma" :value="0"></el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="压缩格式">
        <el-select v-model="form.sRate" placeholder="请选择压缩格式">
          <el-option label="128000" value="shanghai"></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item label="采样率" v-if="false">
        <el-select v-model="form.sRate" placeholder="请选择采样率">
          <el-option label="44.1k" value="441000"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="输入音量" v-if="false">
        <el-col :span="5">
          <el-slider v-model="form.iInputVolumn" show-input></el-slider>
        </el-col>
      </el-form-item>
      <el-form-item label="音频输出开关">
        <el-switch
          v-model="form.iAudioOutputEnable"
          :active-value="activeValue"
          :inactive-value="inactiveValue"
        ></el-switch>
      </el-form-item>
      <el-form-item label="输出音量" prop="iOutputVolumn">
        <el-col :span="5">
          <el-slider v-model="form.iOutputVolumn" show-input></el-slider>
        </el-col>
      </el-form-item>
      <el-form-item label="比对成功提示" prop="iOutputMedia">
        <el-select v-model="form.iOutputMedia" placeholder="请选择比对成功提示">
          <el-option label="欢迎回家" :value="inactiveValue"></el-option>
          <el-option label="请通行" :value="activeValue"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="语音提示" v-if="false">
        <el-row class="time-row">
          <el-col class="" :span="4"> <el-time-picker v-model="form.stime1" placeholder="请选择时间" /></el-col>
          <el-col class="" :span="1"> ~</el-col>
          <el-col class="" :span="4"> <el-time-picker v-model="form.stime2" placeholder="请选择时间" /></el-col>
          <el-col class="" :span="1">
            <el-tag>上午好</el-tag>
          </el-col>
        </el-row>
        <el-row class="time-row">
          <el-col class="" :span="4"> <el-time-picker v-model="form.stime3" placeholder="请选择时间" /></el-col>
          <el-col class="" :span="1"> ~</el-col>
          <el-col class="" :span="4"> <el-time-picker v-model="form.stime4" placeholder="请选择时间" /></el-col>
          <el-col class="" :span="3">
            <el-tag>中午好</el-tag>
          </el-col>
        </el-row>
        <el-row class="time-row">
          <el-col class="" :span="4"> <el-time-picker v-model="form.stime5" placeholder="请选择时间" /></el-col>
          <el-col class="" :span="1"> ~</el-col>
          <el-col class="" :span="4"> <el-time-picker v-model="form.stime6" placeholder="请选择时间" /></el-col>
          <el-col class="" :span="3">
            <el-tag>出行愉快</el-tag>
          </el-col>
        </el-row>
        <el-row class="time-row">
          <el-col class="" :span="4"> <el-time-picker v-model="form.stime7" placeholder="请选择时间" /></el-col>
          <el-col class="" :span="1"> ~</el-col>
          <el-col class="" :span="4"> <el-time-picker v-model="form.stime8" placeholder="请选择时间" /></el-col>
          <el-col class="" :span="3">
            <el-tag>欢迎回家</el-tag>
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {getAudioConfigApi, editAudioConfigApi} from "@/api/config";
import {parseTime} from "@/utils/ruoyi";

export default {
  name: "MvCloudgateTerminalAudioSet",
  data() {
    return {
      activeValue: 1,
      inactiveValue: 0,
      form: {
        iAudioOutputEnable: false,
        sAudioInput: "",
        sCompressFormat: "",
        sRate: "",
        iInputVolumn: 0,
        iAudioInputEnable: false,
        iOutputVolumn: 15,
        iOutputMedia: "",
        stime1:"",
        stime2:"",
        stime3:"",
        stime4:"",
        stime5:"",
        stime6:"",
        stime7:"",
        stime8:"",
      },
      rules: {
        iOutputVolumn: [
          {required: true, message: "输出音量不能为空", trigger: "blur"},
          { pattern:/^[0-9]*$/, trigger: "blur", message: '请输入正整数' },
        ],
        iOutputMedia: [
          {required: true, message: "比对成功提示不能为空", trigger: "blur"},
        ],
      },
    };
  },
  mounted() {
    this.getAudioConfig();
  },
  methods: {
    getAudioConfig() {
      getAudioConfigApi().then((res) => {
        this.form = {...res};
      });
    },
    onSubmit() {
      Object.keys(this.form).forEach((item,index)=>{
        if(item.indexOf('stime')!==-1){
          this.form[item] = parseTime(this.form[item])
        }
      })
      // console.log(this.form)
      editAudioConfigApi(this.form).then((res) => {
        console.log(res);
        this.form = {...res};
        this.$message.success("保存成功");
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.dev-border {
  border: 1px solid red;
}
.time-row{
  margin-bottom: 10px;
}
</style>
